package com.jishuo.nontax.api.socket.handle;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.util.SpringContextUtil;
import com.jishuo.nontax.api.socket.ApiHandle;
import com.jishuo.nontax.bean.vo.BankBalanceVO;
import com.jishuo.nontax.bean.vo.BankPosNewVO;
import com.jishuo.nontax.bean.vo.BankPosVO;
import com.jishuo.nontax.bean.vo.SumPosVO;
import com.jishuo.nontax.bfc.service.BankBalanceService;
import com.jishuo.nontax.bfc.service.BankPosNewService;
import com.jishuo.nontax.bfc.service.BankposService;
import com.jishuo.nontax.bfc.service.SumposService;
import org.dom4j.Element;

import java.math.BigDecimal;

/**
 * @author hlp
 * @date 2023/2/8 15:16
 * @Description:
 */
public class BankPosApi implements ApiHandle {
    @Override
    public BaseResult execute(String head, Element body) {
        if(head.equals("setBankPos")){ // 添加修改  记录银行POS记录
           BankPosVO bankPosVO = new BankPosVO();

            bankPosVO.setBankcheckid(body.selectSingleNode("//root/body/bankcheckid").getText());
            bankPosVO.setAccountnum(body.selectSingleNode("//root/body/accountnum").getText());
            bankPosVO.setAccountname(body.selectSingleNode("//root/body/accountname").getText());
            bankPosVO.setAccountdate(body.selectSingleNode("//root/body/accountdate").getText());
            bankPosVO.setAccounttime(body.selectSingleNode("//root/body/accounttime").getText());
            bankPosVO.setMoney(new BigDecimal(body.selectSingleNode("//root/body/money").getText()));
            bankPosVO.setSummary(body.selectSingleNode("//root/body/summary").getText());
            bankPosVO.setOpaccountnum(body.selectSingleNode("//root/body/opaccountnum").getText());
            bankPosVO.setOpaccountname(body.selectSingleNode("//root/body/opaccountname").getText());
            bankPosVO.setPostscript(body.selectSingleNode("//root/body/postscript").getText());

            BankposService billService = (BankposService) SpringContextUtil.getBean("bankposService");
            BaseResult ret = billService.setBankPos(bankPosVO);
            int n = (ret.isSuccess()) ? 1 : 0;
            ret.setData("<returninfo>"+n+"</returninfo>");
            return ret;


        }else if(head.equals("sendBankPos")){  // 查询pos记录发送到财政
            String accountcode = body.selectSingleNode("//root/body/accountcode").getText();
            String accountdate = body.selectSingleNode("//root/body/accountdate").getText();
            BankposService billService = (BankposService) SpringContextUtil.getBean("bankposService");
            BaseResult ret = billService.sendBankPos(accountcode, accountdate);
            int n = (ret.isSuccess()) ? 1 : 0;
            ret.setData("<returninfo>"+n+"</returninfo>");
            return ret;

        }else if(head.equals("setNewBankPos")){ //记录账户POS明细

            BankPosNewVO bankPosNewVO = new BankPosNewVO();

            bankPosNewVO.setBankaccount(body.selectSingleNode("//root/body/bankaccount").getText());
            bankPosNewVO.setBankaffirm(body.selectSingleNode("//root/body/bankaffirm").getText());
            bankPosNewVO.setClientnum(body.selectSingleNode("//root/body/clientnum").getText());
            bankPosNewVO.setTerminalnum(body.selectSingleNode("//root/body/terminalnum").getText());
            bankPosNewVO.setSysnum(body.selectSingleNode("//root/body/sysnum").getText());
            bankPosNewVO.setTransactiondt(body.selectSingleNode("//root/body/transactiondt").getText());
            bankPosNewVO.setPaybankdt(body.selectSingleNode("//root/body/paybankdt").getText());
            bankPosNewVO.setOpaccountnum(body.selectSingleNode("//root/body/opaccountnum").getText());
            bankPosNewVO.setOpaccountname(body.selectSingleNode("//root/body/opaccountname").getText());
            bankPosNewVO.setAmt(new BigDecimal(body.selectSingleNode("//root/body/amt").getText()));
            BankPosNewService billService = (BankPosNewService) SpringContextUtil.getBean("bankPosNewService");
            BaseResult ret = billService.setNewBankPos(bankPosNewVO);
            int n = (ret.isSuccess()) ? 1 : 0;
            ret.setData("<returninfo>"+n+"</returninfo>");
            return ret;
        }else if(head.equals("sendNewBankPos")){ //查询新pos信息 发送到财政
            String accountcode = body.selectSingleNode("//root/body/accountcode").getText();
            String accountdate = body.selectSingleNode("//root/body/accountdate").getText();

            BankPosNewService billService = (BankPosNewService) SpringContextUtil.getBean("bankPosNewService");
            BaseResult ret = billService.sendNewBankPos(accountcode, accountdate);
            int n = (ret.isSuccess()) ? 1 : 0;
            ret.setData("<returninfo>"+n+"</returninfo>");
            return ret;
        }else if(head.equals("setSumPos")){
            SumPosVO sumPosVO = new SumPosVO();
            sumPosVO.setBankaffirm(body.selectSingleNode("//root/body/bankaffirm").getText());
            sumPosVO.setAccountnum(body.selectSingleNode("//root/body/accountnum").getText());
            sumPosVO.setAccountname(body.selectSingleNode("//root/body/accountname").getText());
            sumPosVO.setAccountdate(body.selectSingleNode("//root/body/accountdate").getText());
            sumPosVO.setAccounttime(body.selectSingleNode("//root/body/accounttime").getText());
            sumPosVO.setMoney(new BigDecimal(body.selectSingleNode("//root/body/money").getText()));
            sumPosVO.setOpaccountnum(body.selectSingleNode("//root/body/opaccountnum").getText());
            sumPosVO.setOpaccountname(body.selectSingleNode("//root/body/opaccountname").getText());
            sumPosVO.setPostscript(body.selectSingleNode("//root/body/postscript").getText());


            SumposService sumposService = (SumposService) SpringContextUtil.getBean("sumposService");
            BaseResult ret = sumposService.setSumPos(sumPosVO);
            int n = (ret.isSuccess()) ? 1 : 0;
            ret.setData("<returninfo>"+n+"</returninfo>");
            return ret;

        }

        return null;
    }
}
